package com.chanzany.state.improve;

import java.util.HashMap;

/**
 * @Author ChanZany
 * @Date 2021/10/20 16:30
 * @Version 1.0
 */
public class ShareContext {
    private ShareState state;
    private HashMap<String, ShareState> stateMap = new HashMap<>();
    public ShareContext(){
        stateMap.put("1",new ConcreteState1());
        stateMap.put("2",new ConcreteState2());
        state = getState("1");
    }

    //设置新状态
    public void setState(ShareState state){
        this.state = state;
    }
    //读取状态
    public ShareState getState(String key) {
        return stateMap.get(key);
    }
    //对请求做处理
    public void handle(){
        state.handle(this);
    }
}
